$(function () {
    $("#hotels-destination").val(sessionStorage.getItem("cityName"));
    $("#keyword").val(sessionStorage.getItem("hotelName"));
    search();
});

$("#searchHotelBtn").click(function () {
    search();
})

function search() {
    var cityName = $("#hotels-destination").val();
    var hotelName = $("#keyword").val();
    $.ajax({
        url: urlAuth + "hotel/hotelSearchBySolr",
        data: {"hotelName":hotelName,"cityName":cityName},
        type: "post",
        headers: {"token":sessionStorage.getItem("token")},
        success:function (data) {
            if (data.success){
                appendResultList(data.data);
            }else{
                location.href="../../login.html";
            }
        }
    });
}



function appendResultList(data) {
    $("#search-result-div").empty();
    var document = "";
    for (var x of data) {
        var star = "";
        for (var j = 1; j <= x.hotelLevel; j++) {
            star += "<i style=\"color:#ff9500\" type=\"ic_new_diamond\" class=\"u-icon u-icon-ic_new_diamond own-star\"></i>";
        }
        document = "<li class=\"list-item-target\">\n" +
            "<div class=\"with-decorator-wrap\">\n" +
            "<div class=\"-border\">\n" +
            "<div class=\"card-item-wrap\">\n" +
            "<div class=\"left\">\n" +
            "<div class=\"list-avatar-wrap\">\n" +
            "<div class=\"special\">\n" +
            "<div class=\"is-tag\"></div>\n" +
            "<div class=\"m-img \" style=\"width:100%;height:100%;\">\n" +
            "<div class=\"preload\"><img src="+x.imgUrl+" /></div>\n" +
            "</div>\n" +
            "</div>\n" +
            "</div>\n" +
            "       <div class=\"info\">\n" +
            "       <div class=\"list-card-tagAndTitle\">\n" +
            "       <div class=\"list-card-title\"><span" +
            "       class=\"name font-bold\">"+x.hotelName+"</span>\n" +
            "       <div class=\"more-star-repeat\">"+star+"</div>" +
            "       <span class=\"badge-thumb badge-thumb-23\"></span>\n" +
            "       </div>\n" +
            "       </div>\n" +
            "                                                                <div class=\"list-card-transport\"><p class=\"transport\"><span\n" +
            "                                                                        class=\"ads\"><span class=\"position\">"+x.address+"</span></span>\n" +
            "                                                                </p></div>\n" +
            "                                                                <div class=\"list-card-tag\"></div>\n" +
            "                                                                <div class=\"list-card-encourage\"></div>\n" +
            "                                                            </div>\n" +
            "                                                        </div>\n" +
            "                                                        <div class=\"right\">\n" +
            "                                                            <div class=\"list-card-comment\">\n" +
            "                                                                <div class=\"me\">\n" +
            "                                                                    <div class=\"describe\"><p\n" +
            "                                                                            class=\"outstanding font-bold\"></p>\n" +
            "                                                                        <p class=\"count\"><a>"+x.recommend_comment.countComment+"条点评</a></p></div>\n" +
            "                                                                    <div class=\"score\"><span\n" +
            "                                                                            class=\"real font-bold\">"+x.recommend_comment.score.toFixed(1)+"</span></div>\n" +
            "                                                                </div>\n" +
            "                                                            </div>\n" +
            "                                                            <div class=\"list-card-price\" role=\"booking\">\n" +
            "                                                                <div class=\"price-area\"><p class=\"price\"><span\n" +
            "                                                                        class=\"p6tagInfo\"></span><span\n" +
            "                                                                        class=\"priceInfo\"></span></p></div>\n" +
            "                                                                <div class=\"select font-bold\" onclick='hotelDetail("+x.id+")'>查看详情</div>\n" +
            "                                                            </div>\n" +
            "                                                        </div>\n" +
            "                                                    </div>\n" +
            "                                                </div>\n" +
            "                                            </div>\n" +
            "</li>";
        $("#search-result-div").append(document);
    }
}


function hotelDetail(id) {
    location.href="../hotelDetail/hotelDetail.html?id="+id;
}

